package org.ethan.lyl.util;

import java.io.File;

/**
 * @Author:Eason Lau
 * @Date:2018/10/31
 * @Description:
 */
public class Path {
    static String path = null;
    public static String SysPath()
    {
        if(path!=null)
            return path;
        path=Path.class.getProtectionDomain().getCodeSource().getLocation().getPath();
        if(path.toUpperCase().indexOf(".JAR")!=-1)
        {
            try
            {
                //截取".JAR第一次出现前的字符串"
                String StrPath=path.substring(0, path.toUpperCase().indexOf(".jar".toUpperCase()));
                System.out.println(StrPath);
                //获取“.jar”包的上一层文件夹
                path=StrPath.substring(0,StrPath.lastIndexOf("/")+1);
            }
            catch(Exception e)
            {
                return "出错了:"+e.toString();
            }
        }
        path = path.replace("file:","").substring(1);
        System.out.println("getPath=" + path);
        return path;
    }
}
